﻿@page "/Fin/OtherOutlay/Approve"
@using nERP.ViewModel.Fin.OtherOutlayVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <Display @bind-Value="@Model.Entity.OtherOutlayCode" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.SupplierId" ShowLabel="true" Lookup="AllSuppliers" />
            <Display @bind-Value="@Model.Entity.MakeUserId" ShowLabel="true" Lookup="AllMakeUsers" />
            <Display @bind-Value="@Model.Entity.InvoicesDate" ShowLabel="true" FormatString="yyyy-MM-dd" />
            <Display @bind-Value="@Model.Entity.SettlementAccountId" ShowLabel="true" Lookup="AllSettlementAccounts" />
            <Display @bind-Value="@Model.Entity.OutlayTypeId" ShowLabel="true" Lookup="AllOutlayTypes" />
            <Display @bind-Value="@Model.Entity.TotalPrice" ShowLabel="true" FormatString="0.##" />
            <Display @bind-Value="@Model.Entity.Remark" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.CreateTime" ShowLabel="true" FormatString="yyyy-MM-dd HH:mm:ss" />
            <Display @bind-Value="@Model.Entity.UpdateTime" ShowLabel="true" FormatString="yyyy-MM-dd HH:mm:ss" />
            <Display @bind-Value="@Model.Entity.CreateBy" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.UpdateBy" ShowLabel="true" />
            <WTUploadImage @bind-Value="@Model.Entity.InvoicesImage" IsDisabled="true" thumb-width="128" />
        </Row>

        <Row>
            <Textarea @bind-Value="@Model.Remark" ShowLabel="true"></Textarea>
        </Row>
        <div class="modal-footer table-modal-footer">
            <Button ButtonType="ButtonType.Submit" IsAsync="true" OnClick="OnAgree" Text="@WtmBlazor.Localizer["Page.同意"]" />
            <Button ButtonType="ButtonType.Submit" IsAsync="true" OnClick="OnDeny" Color="Color.Danger" Text="@WtmBlazor.Localizer["Page.拒绝"]" />
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private OtherOutlayVM Model = new OtherOutlayVM();
    private ValidateForm vform { get; set; }
    public void OnClose()
    {
        CloseDialog();
    }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Fin/OtherOutlay/Approve", (s) => "Sys.OprationSuccess");
    }
    public void OnAgree()
    {
        Model.ActionName = "同意";
        Model.Entity.Status = nERP.Model.StatusTypeEnum.Reviewed;
    }
    public void OnDeny()
    {
        Model.ActionName = "拒绝";
    }


    private List<SelectedItem> AllSuppliers = new List<SelectedItem>();
    private List<SelectedItem> AllMakeUsers = new List<SelectedItem>();
    private List<SelectedItem> AllSettlementAccounts = new List<SelectedItem>();
    private List<SelectedItem> AllOutlayTypes = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllSuppliers = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherOutlay/GetSuppliers");
        AllSuppliers.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllMakeUsers = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherOutlay/GetFrameworkUsers");
        AllMakeUsers.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSettlementAccounts = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherOutlay/GetSettlementAccounts");
        AllSettlementAccounts.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllOutlayTypes = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherOutlay/GetDicFields其他支出类别");
        AllOutlayTypes.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<OtherOutlayVM>($"/api/Fin/OtherOutlay/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
